package com.geek.javase.ch10.work.listwork.work2;

/** 练习2：用LinkedList集合，模拟堆栈操作(存入的元素是Person对象)  先进后出
 **/
public class Test {
    public static void main(String[] args) {
    Stack stack = new Stack();

    Person person1 = new Person(1, "张三", 125);
    Person person2 = new Person(2, "李四", 30);
    Person person3 = new Person(3, "王五", 18);

    // 压栈操作
    stack.push(person1);
    stack.push(person2);
    stack.push(person3);

    // 输出栈的内容
    System.out.println("栈的内容: " + stack);

    // 弹栈操作
    while (!stack.isEmpty()) {
        Person person = stack.pop();
        System.out.println("弹出元素: " + person);
    }

    // 再次输出栈的内容，应该为空
    System.out.println("栈的内容: " + stack);
}
}
